package com.gscitysfy.cus.drain.modules.pipe.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gscitysfy.cus.drain.modules.pipe.entity.CifrsPipeMnPipeline;
import com.gscitysfy.cus.drain.modules.pipe.entity.DrainPipeNetworkPage;
import com.gscitysfy.cus.drain.modules.pipe.mapper.CifrsPipeMnPipelineMapper;
import com.gscitysfy.cus.drain.modules.pipe.service.ICifrsPipeMnPipelineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 * @since 2022-11-15 15:38:27
 */
@Service
@DS("comreposdb")
public class CifrsPipeMnPipelineServiceImpl extends ServiceImpl<CifrsPipeMnPipelineMapper, CifrsPipeMnPipeline> implements ICifrsPipeMnPipelineService {

    @Resource
    private CifrsPipeMnPipelineMapper pipeMnPipelineMapper;

    /**
     * 根据guid查询管道信息
     * @param guids
     * @return
     */
    @Override
    public List<DrainPipeNetworkPage> findPip(List<String> guids) {
        return pipeMnPipelineMapper.findPip(guids);
    }

    /**
     * 计算管网覆盖率
     * @param pipType
     * @param guids
     * @return
     */
    @Override
    public double coverage(String pipType, List<String> guids) {
        String type;
        if("gwlx1".equals(pipType)){
            type = "YS";
        }else if("gwlx2".equals(pipType)) {
            type = "WS";
        }else{
            type = "HS";
        }
        //此类管道总长度
        double total = pipeMnPipelineMapper.countByType(type);

        double pipLen = pipeMnPipelineMapper.countByIds(guids);
        if (total != 0){
            return pipLen / total;
        }else{
            return 0;
        }
    }
}
